
//
// 110515 - AH - (?) Created.
// 110530 - AH - (Chaos) Show title.
// 110605 - AH - (Garage) Removed not used method.
// 110622 - AH - (Bybanen *) Changes because ScanPaintResult no longer has 
//               public member variables, must use get methods.
// 120224 - AH - (Kryddar *) Changes related to that the ScanPaintResult is
//               replaced with ConversationElement.
// 120321 - AH - Removed @Override for interface method (1.5 compatible).
//

package org.soekrat.gui.swing.chat.objectconversation;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.orb.Soekrat2Orb;
import org.soekrat.engine.visitor.Lines;
import org.soekrat.gui.swing.chat.MultiChatPanel;
import org.soekrat.gui.swing.chat.convention.ConventionPanel;

/**
 * <p>
 *   Conversation panel.
 * </p>
 * @author Arne Halvorsen (AH)
 */
@SuppressWarnings("serial")
public final class ConvPanel extends JPanel 
{
  private final ObjectConversationPanel m_ocp;
  
  private final MultiChatPanel m_mcp;
  
  private final ConventionPanel m_cop;
  
  private final Soekrat2Engine m_engine;
  
  private final Soekrat2Orb m_orb;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param engine {@link Soekrat2Engine} interfaced.
   */
  public ConvPanel(Soekrat2Engine engine)
  {
    if (engine==null)
    {
      throw new NullPointerException("engine");
    }
    
    m_orb=(Soekrat2Orb)engine.getAttribute("conversation-element");
    
    m_engine=engine;
    
    m_ocp=new ObjectConversationPanel(engine);
    m_mcp=new MultiChatPanel(engine);
    m_cop=new ConventionPanel(engine);
    
    setLayout(new BorderLayout());
    
    JSplitPane sp=new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(sp, BorderLayout.CENTER);
    
    sp.setLeftComponent(m_ocp);
    sp.setRightComponent(m_mcp);
    
    sp.setDividerLocation(380);
    
    add(m_cop, BorderLayout.SOUTH);
    
    m_mcp.addChangeListener
    (
      new ChangeListener() 
      {
        public void stateChanged(ChangeEvent e) 
        {
          Lines lines=m_mcp.getLines();
          
          m_orb.turnTaking(lines);
          
          m_engine.consult(m_orb.getRealOrb());
          
          m_ocp.add(m_orb);
        }
      }
    );
  }
  
}
